package aps.module_Core;

//Minecraft
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;

//Forge
import cpw.mods.fml.common.network.IGuiHandler;

//APS
import aps.module_Machines.TileEntityGrinder;
import aps.module_Machines.GuiGrinder;
import aps.module_Machines.ContainerGrinder;
import aps.module_Machines.TileEntityMagmafier;
import aps.module_Machines.TileEntityPoweredFurnace;
import aps.module_Converter.ContainerContainerMachine;
import aps.module_Converter.GuiContainerMachine;
import aps.module_Converter.TileEntityContainerMachine;
import aps.module_Fusion.ContainerTokamakGenerator;
import aps.module_Fusion.GuiTokamakGenerator;
import aps.module_Fusion.TileEntityTokamakGenerator;
import aps.module_Machines.ContainerEnergyStore;
import aps.module_Machines.ContainerExtractor;
import aps.module_Machines.GuiEnergyDirector;
import aps.module_Machines.GuiEnergyStore;
import aps.module_Machines.GuiExtractor;
import aps.module_Machines.GuiMagmafier;
import aps.module_Machines.ContainerMagmafier;
import aps.module_Machines.GuiPoweredFurnace;
import aps.module_Machines.ContainerPoweredFurnace;
import aps.module_Machines.TileEntityEnergyDirector;
import aps.module_Machines.TileEntityEnergyStore;
import aps.module_Machines.TileEntityExtractor;


public class GuiHandler implements IGuiHandler{

	@Override
	public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
		
		if (!world.blockExists(x,y,z))
			return null;
		
		TileEntity tile = world.getBlockTileEntity(x, y, z);
		
		switch (ID)
		{
			case GuiIDs.GUI_GRINDER:
				if(!(tile instanceof TileEntityGrinder))
					return null;
				return new GuiGrinder((TileEntityGrinder)tile, player.inventory);
			
			case GuiIDs.GUI_MAGMAFIER:
				if (!(tile instanceof TileEntityMagmafier))
					return null;
				return new GuiMagmafier((TileEntityMagmafier)tile, player.inventory);
				
			case GuiIDs.GUI_POWERFURNACE:
				if (!(tile instanceof TileEntityPoweredFurnace))
					return null;
				return new GuiPoweredFurnace((TileEntityPoweredFurnace)tile, player.inventory);
			
			case GuiIDs.GUI_EXTRACTOR:
				if (!(tile instanceof TileEntityExtractor))
					return null;
				return new GuiExtractor((TileEntityExtractor)tile, player.inventory);
			
			case GuiIDs.GUI_ENERGYDIRECTOR:
				if (!(tile instanceof TileEntityEnergyDirector))
					return null;
				return new GuiEnergyDirector((TileEntityEnergyDirector)tile, player.inventory);
				
			case GuiIDs.GUI_ENERGYSTORE:
				if (!(tile instanceof TileEntityEnergyStore))
					return null;
				return new GuiEnergyStore((TileEntityEnergyStore)tile, player.inventory);
				
			case GuiIDs.GUI_FUSIONREACTOR:
				if (!(tile instanceof TileEntityTokamakGenerator))
					return null;
				return new GuiTokamakGenerator((TileEntityTokamakGenerator)tile, player.inventory);
				
			case GuiIDs.GUI_ENERGYCONTAINER:
				if(!(tile instanceof TileEntityContainerMachine))
					return null;
				return new GuiContainerMachine((TileEntityContainerMachine)tile, player.inventory);
				
			default:
				return null;
		}
	}

	@Override
	public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
		
		if (!world.blockExists(x,y,z)) //&& !world.blockHasTileEntity(x, y, z))
			return null;
		
		//System.out.println(getBlockEntity(x,y,z));
		Object tile = world.getBlockTileEntity(x,y,z);
		
		switch (ID)
		{
			case GuiIDs.GUI_GRINDER:
				if(!(tile instanceof TileEntityGrinder))
					return null;
				return new ContainerGrinder((TileEntityGrinder)tile, player.inventory);
				
			case GuiIDs.GUI_MAGMAFIER:
				if (!(tile instanceof TileEntityMagmafier))
					return null;
				return new ContainerMagmafier((TileEntityMagmafier)tile, player.inventory);
			
			case GuiIDs.GUI_POWERFURNACE:
				if (!(tile instanceof TileEntityPoweredFurnace))
					return null;
				return new ContainerPoweredFurnace((TileEntityPoweredFurnace)tile, player.inventory);
			
			case GuiIDs.GUI_EXTRACTOR:
				if (!(tile instanceof TileEntityExtractor))
					return null;
				return new ContainerExtractor((TileEntityExtractor)tile, player.inventory);
			
			case GuiIDs.GUI_ENERGYDIRECTOR:
				if (!(tile instanceof TileEntityEnergyDirector))
					return null;
				return new ContainerAPS(player.inventory);
				
			case GuiIDs.GUI_ENERGYSTORE:
				if (!(tile instanceof TileEntityEnergyStore))
					return null;
				return new ContainerEnergyStore((TileEntityEnergyStore)tile, player.inventory);
				
			case GuiIDs.GUI_FUSIONREACTOR:
				if (!(tile instanceof TileEntityTokamakGenerator))
					return null;
				return new ContainerTokamakGenerator((TileEntityTokamakGenerator)tile, player.inventory);
			
			case GuiIDs.GUI_ENERGYCONTAINER:
				if (!(tile instanceof TileEntityContainerMachine))
					return null;
				return new ContainerContainerMachine((TileEntityContainerMachine)tile, player.inventory);
				
			default:
				return null;
		}
	}
}
